# -*- coding:utf-8 -*-
"""
# @author = JeffXun
# @date   = 2011-10-08
"""

"""
# 模块导入部分
"""
import xlrd # Excel操作模块
class Excel:
    """ Excel """
    def __init__(self,filename):
        """ Open Excel"""
        self.Excel  = None
        try:
            self.Excel = xlrd.open_workbook(filename)
        except Exception,e:
            print e

    def gettablerows(self,table):
        """
        #获取当前单元表的行数
        #@table:当前表对象
        """
        return table.nrows

    def UpdateExcel(self,sheetindex = 0 ):
        """
        # 读取Excel文件每个单元表的内容
        # @sheetindex:表示读取的单元标的索引值
        """
        table = self.Excel.sheets()[sheetindex]
        result = []
        for index in range(1,self.gettablerows(table)):
            tmp = table.row_values(index)
            #print tmp
            #break
            #print tmp
            result.append(tmp)
            #result[int(tmp[0])] = tmp
            #break;
        return result
    def GetExcelByDict(self,sheetindex=0):
        """ """
        table = self.Excel.sheets()[sheetindex]
        keys = table.row_values(0)
        result = []
        for index in range(1,self.gettablerows(table)):
            tmp = table.row_values(index)
            line = []
            for i in range(len(keys)):
                line.append({keys[i]:tmp[i]})
            result.append(line)
        return result

if __name__ == "__main__":
    a = Excel("../../config/npc.xls")
    print a.GetExcelByDict(0)